#管理员工接口案例参数化
import pytest
import requests
import logging
from api.ihrmEmpManageApi import EmpManageApi
from common.DBT框架 import DBTools
from common.assertTools import common_assret
from common.getHeader import get_header
from common.readJsonTools import read_json_filr
from config import TEL, project_path


class TestAddEmp(object):
    def setup_class(self):
        self.emp = EmpManageApi()
    req_header=get_header()

    def setup(self):
        DBTools.db_iud(f"delete from bs_user where mobile ='{TEL}'")   #开始删除一次不重复
    def teardown(self):
        DBTools.db_iud(f"delete from bs_user where mobile ='{TEL}'") #测试后删除一次不保留


    filename = project_path + "/data/addihrm.json"
    data=read_json_filr(filename)


    @pytest.mark.parametrize("desc,req_body,status_code,success,code,message",data)
    def test_add_success(self,desc,req_body,status_code,success,code,message):

         # 添加员工
         resp =self.emp.add_emp(self.req_header, req_body)
         print(desc,":",resp.json())
         logging.info(f"{desc},{resp.json()}")
         common_assret(resp, status_code,success,code,message)

#第一步准备JSON文件
#第二步读文件 改文件名就行
#第三步加入通用方法传参数(参数一是 Json文件的键值,参数2读的数据) 参数2调取读的方法 (在调取文件的路径给传参)
#第四步 键直接复制到参数中
#第五步参数放入方法中
    # def test02_mobile_none(self): #手机号空
    #
    #      # 添加员工
    #      req_body = {"username": "张三疯007", "mobile": None, "workNumber": "9527"}
    #      resp = self.emp.add_emp(self.req_header, req_body)
    #      print("添加成功:", resp.json())
    #
    #      common_assret(resp, 200, False, 20002, "新增员工失败")
    # def test03_no_params(self):#无参
    #
    #      # 添加员工
    #      req_body =None
    #      resp =self. emp.add_emp(self.req_header, req_body)
    #      print("添加成功:", resp.json())
    #
    #      common_assret(resp, 200, False, 99999, "抱歉，系统繁忙，请稍后重试")